
#include <stdio.h>
#include <stdlib.h>
#include <errnoLib.h>
#include <timers.h>
#include <time.h>
#include <signal.h>

#include "vxWorks.h"
#include "taskLib.h"
#include "sysLib.h"
#include "sigLib.h"
#include "logLib.h"
#include "ioLib.h"



int fdl;


char * timeX(void)
{
	
	static struct timespec timeNow;
	clock_gettime(CLOCK_REALTIME, &timeNow);/*gets the current time and stores in rtclk_start_time*/
	return 	ctime(&(timeNow.tv_sec));


}


void logT(void)
{

	 int stdOutSaver; 
	 
	fdl = open("/home/jayson/log.txt",O_WRONLY|O_CREAT, 0644);

	 if (fdl == ERROR) {
	        printf("Log file errord\n");
	      } 
	 else {
	        printf("Log file is open\n");
	        logFdAdd(fdl);
	     
	        
	        stdOutSaver=ioGlobalStdGet(1);   
	        ioGlobalStdSet(1,fdl);
	        
	        
	        
	logMsg("in logfile\n",0,0,0,0,0,0);
	logMsg("in logfile again\n",0,0,0,0,0,0);
	logMsg("in logfile again and again :%d \n",ioGlobalStdGet(1),0,0,0,0,0);

	ioGlobalStdSet(1, stdOutSaver);
	logFdDelete(fdl);
	close(fdl);

	

	logMsg("not in  logfile\n",0,0,0,0,0,0);
	 }
		
	
	
}


void spw(void)
{
	 if(taskSpawn("logger", 90, 0, 4000, logT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) == ERROR) {
	    printf(" task spawn failed\n");
	  }
	  else
	    printf(" task spawned\n");

    
    
}
